Skip to content

fix: handle GitHub API error response in ContributorProfile#623

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Dhruvg0:fix/contributor-profile-api-error
May 31, 2026
Merged

fix: handle GitHub API error response in ContributorProfile#623
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Dhruvg0:fix/contributor-profile-api-error

Conversation

@Dhruvg0
Copy link
Copy Markdown
Contributor

@Dhruvg0 Dhruvg0 commented May 31, 2026

Related Issue

  • Closes: #

Description

When the GitHub API returns an error (e.g. user not found, rate limit exceeded),
the response is { message: 'Not Found' } instead of a valid user object.
The component was accessing profile.avatar_url on this error object, causing
a runtime crash. Added a guard to throw a proper error before any profile
properties are accessed.


How Has This Been Tested?

Manually tested by entering a non-existent GitHub username. Without the fix
the app crashes. With the fix an error is thrown and handled gracefully.


Screenshots (if applicable)

N/A


Type of Change

  • Bug fix

Summary by CodeRabbit

  • Bug Fixes
    • Fixed error handling when fetching GitHub user data to ensure error messages are properly displayed to users.

Copilot AI review requested due to automatic review settings May 31, 2026 02:45
@netlify
Copy link
Copy Markdown

netlify Bot commented May 31, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 9cca5c7
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a1ba111e394190008d3c67d
😎 Deploy Preview https://deploy-preview-623--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

Warning

Review limit reached

@Dhruvg0, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 49 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: addea53d-d759-412c-b829-bcb56a9c1059

📥 Commits

Reviewing files that changed from the base of the PR and between d5a12f1 and 9cca5c7.

📒 Files selected for processing (1)
  • src/pages/ContributorProfile/ContributorProfile.tsx
📝 Walkthrough

Walkthrough

ContributorProfile's GitHub user data fetch now explicitly validates the response payload. When the GitHub API returns an error structure (indicated by the presence of userData.message), the code throws an error, which the existing error handler catches and displays as a user-facing toast notification.

Changes

GitHub API Error Handling

Layer / File(s) Summary
GitHub error payload detection
src/pages/ContributorProfile/ContributorProfile.tsx
Added guard check to detect GitHub API error responses via userData.message and throw, triggering the existing catch handler to report "Failed to fetch user data."

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

  • GitMetricsLab/github_tracker#622: Directly addresses the proposed fix for handling GitHub API { message: ... } error responses in the ContributorProfile fetch flow.

Possibly related PRs

  • GitMetricsLab/github_tracker#484: Both PRs update src/pages/ContributorProfile/ContributorProfile.tsx's GitHub data-loading logic to treat failed API responses as errors, overlapping in the same fetch/error-handling checkpoint.

Suggested labels

quality:clean, gssoc:approved, level:beginner

Poem

🐰 A tiny guard check hops in place,
To catch GitHub's error-laden face,
One line of code, so clean and bright,
Makes failed requests show up right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: handling GitHub API error responses in the ContributorProfile component, which aligns with the code modification described in the summary.
Description check ✅ Passed The description follows the template structure and includes all required sections: Related Issue, Description, Testing, Screenshots, and Type of Change, with substantive content explaining the bug fix and testing approach.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds basic error handling to the GitHub user fetch in the ContributorProfile page so API error responses (e.g., rate limiting, user not found) are surfaced instead of being silently set as profile data.

Changes:

  • Throws an error when the GitHub users API response contains a message field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/ContributorProfile/ContributorProfile.tsx Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Thank you @Dhruvg0 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/ContributorProfile/ContributorProfile.tsx (1)

33-37: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Missing error handling for PR search will cause runtime crash.

The PR search endpoint can also return GitHub API error responses (e.g., rate limits, invalid queries), but unlike the user fetch, there's no error check here. If prsData.items is undefined (because the response was an error object), line 79 will crash with TypeError: Cannot read property 'length' of undefined.

🐛 Proposed fix
 const prsRes = await fetch(
   `https://api.github.com/search/issues?q=author:${username}+type:pr`
 );
 const prsData = await prsRes.json();
+if (prsData.message) throw new Error(prsData.message);
 setPRs(prsData.items);

Or, applying the same HTTP status check pattern:

 const prsRes = await fetch(
   `https://api.github.com/search/issues?q=author:${username}+type:pr`
 );
+if (!prsRes.ok) {
+  throw new Error(`GitHub API error: ${prsRes.status} ${prsRes.statusText}`);
+}
 const prsData = await prsRes.json();
 setPRs(prsData.items);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/ContributorProfile/ContributorProfile.tsx` around lines 33 - 37,
The PR search fetch in ContributorProfile (variables prsRes, prsData, setPRs and
the template using username) is missing HTTP/error handling; update the PR fetch
to check prsRes.ok (or status) before reading prsData, and if the response is
not ok or prsData.items is undefined, log or surface the error and call
setPRs([]) (or a safe fallback) instead of using prsData.items directly so
subsequent code doesn't crash when items is missing. Ensure you reuse the same
error-check pattern used for the user fetch: await prsRes.json(), verify
prsRes.ok, handle non-OK responses (including rate limit/error objects) and set
a safe empty array via setPRs when necessary.
🧹 Nitpick comments (1)
src/pages/ContributorProfile/ContributorProfile.tsx (1)

28-30: ⚡ Quick win

Recommend checking HTTP status code before parsing JSON.

While the userData.message check catches GitHub API error responses, it's more robust and idiomatic to verify the HTTP status code before parsing the response body. This approach also handles edge cases like network errors or malformed responses.

🛡️ Proposed enhancement
 const userRes = await fetch(`https://api.github.com/users/${username}`);
+if (!userRes.ok) {
+  throw new Error(`GitHub API error: ${userRes.status} ${userRes.statusText}`);
+}
 const userData = await userRes.json();
-if (userData.message) throw new Error(userData.message);
 setProfile(userData);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/ContributorProfile/ContributorProfile.tsx` around lines 28 - 30,
Check the HTTP response status before parsing JSON in ContributorProfile.tsx:
after awaiting fetch for `userRes` (the call using `username`), verify
`userRes.ok` (or `userRes.status`) and throw a descriptive Error (include
`userRes.status` and `userRes.statusText`) if it's not ok, then call `await
userRes.json()` only for successful responses; update the error handling instead
of relying on `userData.message`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/pages/ContributorProfile/ContributorProfile.tsx`:
- Around line 33-37: The PR search fetch in ContributorProfile (variables
prsRes, prsData, setPRs and the template using username) is missing HTTP/error
handling; update the PR fetch to check prsRes.ok (or status) before reading
prsData, and if the response is not ok or prsData.items is undefined, log or
surface the error and call setPRs([]) (or a safe fallback) instead of using
prsData.items directly so subsequent code doesn't crash when items is missing.
Ensure you reuse the same error-check pattern used for the user fetch: await
prsRes.json(), verify prsRes.ok, handle non-OK responses (including rate
limit/error objects) and set a safe empty array via setPRs when necessary.

---

Nitpick comments:
In `@src/pages/ContributorProfile/ContributorProfile.tsx`:
- Around line 28-30: Check the HTTP response status before parsing JSON in
ContributorProfile.tsx: after awaiting fetch for `userRes` (the call using
`username`), verify `userRes.ok` (or `userRes.status`) and throw a descriptive
Error (include `userRes.status` and `userRes.statusText`) if it's not ok, then
call `await userRes.json()` only for successful responses; update the error
handling instead of relying on `userData.message`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 404e2760-9fd2-4b08-9e2d-78b2b8874be6

📥 Commits

Reviewing files that changed from the base of the PR and between e7b8fc8 and d5a12f1.

📒 Files selected for processing (1)
  • src/pages/ContributorProfile/ContributorProfile.tsx

@mehul-m-prajapati mehul-m-prajapati merged commit 8d1f6f6 into GitMetricsLab:main May 31, 2026
6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #623 has been merged! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants